﻿using Quartz;
using Quartz.Impl.Triggers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JinJun.YShowReception.Core;

namespace JinJun.YShowReception.JobScheduler.Common
{
   public class JobSchedulerManager
    {

        /// <summary>
        /// 负责任务调度
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sched"></param>
        /// <param name="croname"></param>
        /// <param name="trigroup"></param>
        /// <param name="trigGroupName"></param>
        public static void AddScheduler<T>(ref IScheduler sched,string croname,string trigroup, string trigGroupName)where T:IJob
        {
            var jobKey = new JobKey(croname + "key", trigroup);
            //创建调度服务
            var jobDetail = JobBuilder.Create<T>().WithIdentity(jobKey).Build();
            //设置调度时间间隔
            var jobTrig = new CronTriggerImpl(croname + "Trig", trigGroupName, ConfigurationHelper.GetSectionValue("Crons", croname));
            sched.ScheduleJob(jobDetail, jobTrig);
        }
    }
}
